<template>
    <Form ref="carInfo" :label-width="160" :model="carInfo" label-position="right"  inline >
        <div>
            <Row>
                <Button @click="saveOldCarInfo" style="float: right" type="success" v-if="isCheck">保存</Button>
            </Row>
            <Row>
                <Col span="8">
                    <FormItem prop="brandName" label="品牌">
                        <Input type="text" v-model="carInfo.brandName" disabled placeholder="请输入">
                        </Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem prop="modelName" label="车型">
                        <Poptip placement="bottom" v-if="carInfo.backSign==='yes'&&carInfo.modelName!==carInfo.modelNameOld" >
                            <Input type="text" v-model="carInfo.modelName" disabled placeholder="请输入" icon="ios-warning">
                            </Input>
                            <div slot="title" style="font-weight: 700;width: 175px">{{carInfo.modelNameOld}}</div>
                        </Poptip>
                        <Input v-if="carInfo.backSign!=='yes'||carInfo.modelName===carInfo.modelNameOld" type="text" v-model="carInfo.modelName" disabled placeholder="请输入" style="width: 175px">
                        </Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem prop="carColor" label="车辆颜色">
                            <Input type="text" v-model="carInfo.carColor" disabled placeholder="请输入"></Input>
                    </FormItem>
                </Col>
            </Row>
            <Row>
                <Col span="24">
                    <FormItem prop="styleName" label="款式">
                        <div style="display: flex; flex-flow: row;">
                            <Poptip placement="bottom" v-if="carInfo.backSign==='yes'&&carInfo.styleName!==carInfo.styleNameOld" >
                                <Input type="text" v-model="carInfo.styleName" disabled placeholder="请输入" icon="ios-warning">
                                </Input>
                                <div slot="title" style="font-weight: 700">{{carInfo.styleNameOld}}</div>
                            </Poptip>
                            <Input v-if="carInfo.backSign!=='yes'||carInfo.styleName===carInfo.styleNameOld" type="text" style="width: 590px" v-model="carInfo.styleName" disabled placeholder="请输入">
                            </Input>
                            <Button @click="showCarStyleDetailInfo" ghost type="success" style="margin-left: 5px">查看配置</Button>
                        </div>
                    </FormItem>
                </Col>
            </Row>
            <Row>
                <Col span="8">
                    <FormItem prop="engineNo" label="发动机号">
                        <Input type="text" v-model="carInfo.engineNo" disabled placeholder="请输入">
                        </Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem prop="fullModelNum" label="车辆型号">
                        <Input type="text" v-model="carInfo.fullModelNum" disabled placeholder="请输入">
                        </Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem prop="carBodyClass" label="车身类型">
                        <Input type="text" v-model="carInfo.carBodyClass" disabled placeholder="请输入">
                        </Input>

                    </FormItem>
                </Col>
            </Row>
            <Row>
                <Col span="8">
                    <FormItem prop="carVin" label="VIN号">
                        <Poptip placement="bottom" v-if="carInfo.warningInfo.vin.showflag" >
                            <Input type="text" style="width: 180px"  v-model="carInfo.carVin" disabled placeholder="请输入" icon="ios-warning">
                            </Input>
                            <div slot="title" >{{carInfo.warningInfo.vin.title}}</div>
                            <div slot="content">
                                <li v-for="item in carInfo.warningInfo.vin.msgs">{{item.submissionTime}}&nbsp&nbsp{{item.applicationNo}}&nbsp&nbsp{{item.borrower}}&nbsp&nbsp{{item.statusName}}</li>
                            </div>
                        </Poptip>
                        <Input type="text" style="width: 180px" v-if="!carInfo.warningInfo.vin.showflag"  v-model="carInfo.carVin" disabled placeholder="请输入">
                        </Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem prop="fuelType" label="燃油种类">
                        <Select v-model="carInfo.fuelType" disabled placeholder="请选择">
                            <Option v-for="item in dataDic.fuelType" :label="item.title" :value="item.value" :key="item.value">{{ item.title }}</Option>
                        </Select>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem prop="carTransmission" label="变速器">
                        <Select v-model="carInfo.carTransmission" disabled placeholder="请选择">
                        <Option v-for="item in dataDic.carTransmission" :label="item.title" :value="item.value" :key="item.value">{{ item.title }}</Option>
                       </Select>
                    </FormItem>
                </Col>
            </Row>
            <Row>
                <Col span="8">
                    <FormItem prop="carFunction" label="使用性质">
                        <Select v-model="carInfo.carFunction" disabled placeholder="请选择">
                            <Option v-for="item in dataDic.carFunction" :label="item.title" :value="item.value" :key="item.value">{{ item.title }}</Option>
                        </Select>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem prop="carDisplacement" label="排量（T/L）">
                        <Input type="text" v-model="carInfo.carDisplacement" disabled placeholder="请输入">
                        </Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem prop="salePrice" label="新车指导价格">
                        <Input type="text" v-model="carInfo.guidePrice" disabled placeholder="请输入">
                        </Input>
                    </FormItem>
                </Col>
            </Row>
            <Row>
                <Col span="8">
                    <FormItem prop="carPurpose" label="购车目的">
                        <Select v-model="carInfo.carPurpose" disabled placeholder="请选择">
                            <Option v-for="item in dataDic.carPurpose" :label="item.title" :value="item.value" :key="item.value">{{ item.title }}</Option>
                        </Select>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem prop="totalPassenger" label="核定载客">
                        <Input type="text" v-model="carInfo.totalPassenger" disabled placeholder="请输入">
                        </Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem prop="secondSalePrice" label="二手车销售价格">
                        <Input type="text" v-model="carInfo.secondSalePrice" disabled placeholder="请输入">
                        </Input>
                    </FormItem>
                </Col>
            </Row>
            <Row>
                <Col span="8">
                    <FormItem prop="purchaseAddress" label="购车地点">
                        <Input type="text" v-model="carInfo.purchaseAddress" disabled placeholder="请输入">
                        </Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem prop="carBelongs" label="所有人">
                        <Input type="text" v-model="carInfo.carBelongs" disabled placeholder="请输入">
                        </Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem prop="evaluatingPrice" label="评估价格">
                        <Input type="number" v-model="carInfo.evaluatingPrice" placeholder="请输入"  :disabled="!isCheck">
                        </Input>
                    </FormItem>
                </Col>
            </Row>
            <Row>
                <Col span="8">
                    <FormItem prop="plateAddress" label="上牌地点">
                        <i-select style="width: 150px" v-model="carInfo.licenseProvince" placement="top" placeholder="请选择" @on-change="queryCity" :disabled="!isCheck">
                            <i-option v-for="(item,index) in provinces" style="width: 150px" :label="item.label" :value="item.value" :key="index">{{ item.label }}</i-option>
                        </i-select>
                        <Select style="width: 150px" v-model="carInfo.licenseCity" placement="top" placeholder="请选择" :disabled="!isCheck">
                            <Option v-for="(item,index) in cities" style="width: 150px" :label="item.label" :value="item.value" :key="index">{{ item.label }}</Option>
                        </Select>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem prop="belongsCertNo" label="所有人证件号">
                        <Input type="text" v-model="carInfo.belongsCertNo" disabled placeholder="请输入">
                        </Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem prop="loanAmtMax" label="理论最大贷款额">
                        <Input type="text" v-model="carInfo.loanAmtMax" disabled placeholder="请输入">
                        </Input>
                        <Button style="margin-left:5px" ghost type="success" @click="claculateLoanAmtMax" icon="md-calculator">
                        </Button>
                    </FormItem>
                </Col>
            </Row>
        </div>
        <div>
            <Alert type="warning">车辆手续信息</Alert>
            <Row>
                <Col span="8">
                    <FormItem prop="licensePlate" label="车牌号">
                        <Input type="text" v-model="carInfo.licensePlate" disabled placeholder="请输入">
                        </Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem prop="carAppraiser" label="评估师">
                        <Input type="text" v-model="carInfo.carAppraiser" disabled placeholder="请输入">
                        </Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem prop="mileage" label="表显里程（公里）">
                        <Input type="text" v-model="carInfo.mileage" disabled placeholder="请输入">
                        </Input>
                    </FormItem>
                </Col>
            </Row>
            <Row>
                <Col span="8">
                    <FormItem prop="carDealerName" label="车商姓名">
                        <Input type="text" v-model="carInfo.carDealerName" disabled placeholder="请输入">
                        </Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem prop="carDealerPhone" label="车商联系方式">
                        <Input type="text" v-model="carInfo.carDealerPhone" disabled placeholder="请输入">
                        </Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem prop="carDealerAddress" label="车商联系地址">
                        <Input type="text" v-model="carInfo.carDealerAddress" disabled placeholder="请输入">
                        </Input>
                    </FormItem>
                </Col>
            </Row>
            <Row>
                <Col span="8">
                    <FormItem prop="yearTransNum" label="一年内过户次数">
                        <Input type="text" v-model="carInfo.yearTransNum" disabled placeholder="请输入">
                        </Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem prop="transNums" label="总过户次数">
                        <Input type="text" v-model="carInfo.transNums" disabled placeholder="请输入">
                        </Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem prop="drivingLicenceNo" label="注册地点">
                        <Input type="text" v-model="carInfo.registAddress" disabled placeholder="请输入">
                        </Input>
                    </FormItem>
                </Col>
            </Row>
            <Row>
                <Col span="8">
                    <FormItem prop="isCirTrans" label="是否循环过户">
                        <Select v-model="carInfo.isCirTrans" disabled placeholder="请选择">
                            <Option v-for="item in dataDic.isType" :label="item.title" :value="item.value" :key="item.value">{{ item.title }}</Option>
                        </Select>
                    </FormItem>
                </Col>
                <Col span="16">
                    <FormItem prop="firstLandingDate" label="首次登记日期">
                        <DatePicker type="date" v-model="carInfo.firstLandingDate" disabled placeholder="选择日期"></DatePicker>
                    </FormItem>
                </Col>
            </Row>
            <Row>
                <Col span="24">
                    <FormItem prop="isMortgage" label="是否抵押">
                        <Select v-model="carInfo.isMortgage" disabled placeholder="请选择">
                            <Option v-for="item in dataDic.whetherStatus" :label="item.title" :value="item.value" :key="item.value">{{ item.title }}</Option>
                        </Select>
                    </FormItem>
                </Col>
            </Row>
        </div>
    </Form>
</template>

<script>
    import {
        getByTypes
    } from "_p/basic/api/admin/datadic";
    import {
        getAddressList
    } from "../../../../api/afs-case/infomationDetail/applyCustomerDetail";
    import {
        queryCarDetailInfo,
        claculateLoanAmtMax,
        saveOldCarInfo
    } from "@/projects/afs-core-business/api/afs-case/infomationDetail/carDetail";
    export default {
        name: "old-car-detail",
        components: {
        },
        props: {
            applyNo: {
                type: String,
                required: true
            },
            isCheck: {
                type: Boolean
            }
        },
        data:function () {
            return {
                applyNumber:this.applyNo,
                hasAffix :false,
                provinceLevel: "1",
                provinces:{},
                cities: {},
                dicKeys: [
                    "fuelType","carFunction","carPurpose","isType","carTransmission","whetherStatus","carBodyClass"
                ],
                dataDic:{},
                carInfo:{
                    warningInfo:{
                        vin:{
                            showflag:"",
                            title:"",
                            msgs:[]
                        },
                        price:{
                            showflag:"",
                            title:"",
                            msgs:[]
                        }
                    }
                }
            }
        },
        methods:{
            showCarStyleDetailInfo(){
                this.$emit('function',this.carInfo.carId);
            },
            updateTotalLoanAmtInfo(loanAmtMax){
                this.$emit('maxLoan',loanAmtMax);
            },
            initDataDic(){
                let self = this;
                getByTypes(this.dicKeys).then(res => {
                    if (res.code === "0000" && res.data) {
                        self.dataDic = res.data;
                    }
                });
            },
            //查省份
            initQueryProvince() {
                let params = {
                    level: this.provinceLevel
                }
                getAddressList(params).then(res => {
                    if (res.code === "0000") {
                        this.provinces = res.data;
                    }
                });
            },
            //查城市
            queryCity(val){
                let params = {
                    upperCode: val
                }
                getAddressList(params).then(res => {
                    if (res.code === "0000") {
                        this.cities = res.data;
                    }
                });
            },
            //更新车辆信息
            saveOldCarInfo(){
                if (this.carInfo.licenseCity ==="" || this.carInfo.licenseCity === undefined) {
                    this.$Message.error("请输入上牌地点")
                    return;
                }
                if (this.carInfo.evaluatingPrice ==="" || this.carInfo.evaluatingPrice === undefined) {
                    this.$Message.error("请输入评估价格")
                    return;
                }
                this.$Modal.confirm({
                    title: "保存车辆信息",
                    content: "确定保存当前车辆信息?",
                    onOk: () => {
                        let params = {
                            carId: this.carInfo.id,
                            licenseProvince: this.carInfo.licenseProvince,
                            licenseCity: this.carInfo.licenseCity,
                            evaluatingPrice: this.carInfo.evaluatingPrice
                        }
                        saveOldCarInfo(params).then(res =>{
                            if (res.code === "0000") {
                                this.$Message.success("保存成功");
                                this.initInfo();
                            }else {
                                this.$Message.error("保存失败");
                            }
                        });
                    }
                });
            },
            initInfo(){
                let params = {
                    applyNo: this.applyNumber
                }
                queryCarDetailInfo(params).then(res => {
                    if (res.code === "0000") {
                        this.carInfo = res.data;
                        this.queryCity(this.carInfo.licenseProvince)
                    }
                });
            },
            claculateLoanAmtMax(){
                if(this.carInfo.evaluatingPrice===""|| typeof (this.carInfo.evaluatingPrice)==='undefined'){
                    this.$Message.success("试算失败，评估价格为空！");
                    return true;

                }
                let params = {
                    applyNo: this.applyNumber,
                    carId:this.carInfo.carId,
                    evaluatingPrice:this.carInfo.evaluatingPrice
                }
                this.$Spin.show();
                claculateLoanAmtMax(params).then(res => {
                    this.$Spin.hide();
                    if (res.code === "0000") {
                        this.carInfo.loanAmtMax = res.data.loanAmtMax;
                        this.updateTotalLoanAmtInfo(res.data.loanAmtMax);
                    }
                });
            },
            init() {
                this.initDataDic();
                this.initInfo();
                this.initQueryProvince();
            },
        },
        mounted() {
            this.init();
        }
    }
</script>

<style scoped>

</style>
